package ohc.login.mixin;

import net.minecraft.network.ClientConnection;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ConnectedClientData;
import net.minecraft.server.network.ServerPlayerEntity;
import ohc.login.FakePlayerManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
 * 拦截玩家加入事件，处理假人自动登录
 */
@Mixin(PlayerManager.class)
public class PlayerManagerMixin {
    
    @Inject(method = "onPlayerConnect", at = @At("TAIL"))
    private void onPlayerConnect(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) {
        // 先设置未登录称号（清除旧称号）
        FakePlayerManager.INSTANCE.setNotLoggedInPrefix(player);
        // 尝试假人自动登录
        FakePlayerManager.INSTANCE.tryAutoLogin(player);
    }
}
